package dongbai.soft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dongbai.soft.dao.SupplierDao;
import dongbai.soft.entity.SupplierEntity;
import dongbai.soft.service.SupplierService;
import dongbai.soft.utils.Constant;
import dongbai.soft.utils.PageUtils;
import dongbai.soft.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("supplierService")
public class SupplierServiceImpl extends ServiceImpl<SupplierDao, SupplierEntity> implements SupplierService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SupplierEntity> page = this.page(
                new Query<SupplierEntity>().getPage(params),
                new QueryWrapper<SupplierEntity>().eq("status", Constant.STATE_Y)
                        .like("name", params.get("name"))
        );

        return new PageUtils(page);
    }

    @Override
    public boolean DUP(String name) {
        return this.getOne(new QueryWrapper<SupplierEntity>().eq("name", name).eq("status", Constant.STATE_Y)) != null;
    }

}